package org.nextive.android.weightapp.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbOpenHelper extends SQLiteOpenHelper 
{
	public static final String DATABASE_NAME = "weightapp.db";
	public static final String TABLE_WEIGHTS = "weights";
	
	public static final String CREATE_TABLE_WEIGHTS = 
		"CREATE TABLE " + TABLE_WEIGHTS + " (_id INTEGER PRIMARY KEY autoincrement," +
											"date TEXT UNIQUE,"+
											"weight REAL);";
	
	public static final String DELETE_TABLE_WEIGHTS = "DROP TABLE IF EXISTS weights;";

	public DbOpenHelper(Context context) 
	{
		super(context, DATABASE_NAME, null, 1);
	}

	@Override
	public void onCreate(SQLiteDatabase database) 
	{
		database.execSQL(CREATE_TABLE_WEIGHTS);
	}

	@Override
	public void onUpgrade(SQLiteDatabase database, int arg1, int arg2) 
	{
		database.execSQL(DELETE_TABLE_WEIGHTS);
        onCreate(database);
	}
}
